package timeslice
{
	import away3d.events.AssetEvent;
	import away3d.events.LoaderEvent;
	import away3d.library.AssetLibrary;
	import away3d.loaders.parsers.AWD2Parser;
	
	import flash.net.URLRequest;
	
	import globals.$config;
	
	import slices.TimeSlice;
	
	public class LoadMapResource extends TimeSlice
	{
		private var _count:int; 
		
		public function LoadMapResource()
		{
			super();
		}
		
		override public function onStart():void {
			AssetLibrary.enableParser(AWD2Parser);
			AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);
			AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceComplete);
			AssetLibrary.addEventListener(LoaderEvent.LOAD_ERROR, onLoadError);
			AssetLibrary.load(new URLRequest($config.ResourceRoot+"max/test/MaxAWDWorkflow.awd"), null, "hero");
//			AssetLibrary.load(new URLRequest($config.ResourceRoot+"max/model/m1.awd"));
			AssetLibrary.load(new URLRequest($config.ResourceRoot+"max/model/PolarBear.awd"), null, "bear");
			AssetLibrary.load(new URLRequest($config.ResourceRoot+"max/c1/m1.awd"), null, "map");
			_count = 3;
		}
		
		protected function onLoadError(event:LoaderEvent):void
		{
			trace("Error loading: " + event.url);
		}
		
		private function onAssetComplete(event:AssetEvent):void
		{
			// To not see these names output in the console, comment the
			// line below with two slash'es, just as you see on this line
			trace("Loaded " + event.asset.name + " Name: " + event.asset.name);
		}
		
		private function onResourceComplete(ev:LoaderEvent):void
		{
			//			assetsThatAreloaded++;
			// check to see if we have all we need
			//			if (assetsThatAreloaded == assetsToLoad) {
//			setupScene();
			//			}
			//			view.render();
			_count--;
			if (_count == 0)
				isEnd = true;
		}
	}
}